package com.kangkang.leetcode20;

import java.util.Arrays;

public class Test238 {
    public static void main(String[] args) {
        int[] a = {-1,1,0,-3,3};
        System.out.println(Arrays.toString(Solution238.productExceptSelf(a)));
    }
}
class Solution238 {
    public static int[] productExceptSelf(int[] nums) {
        int[] a = new int[nums.length];
        a[0] = 1;
        for (int i = 1; i < a.length; i++) {
            a[i] = a[i-1] * nums[i-1];
        }
        int temp = nums[nums.length-1];
        for (int i = a.length-2; i >= 0; i--) {
            a[i] = a[i] * temp;
            temp *= nums[i];
        }
        return a;
    }
}